home *** CD-ROM | disk | FTP | other *** search
- /*
- Test mappings
- */
-
- #include "Instructions.h"
- #include "Wavy.h"
-
- #include <QDOffscreen.h>
- #include <FixMath.h>
-
- static void
- MakeWavyTable(short amplitude, short wavyTable[32])
- {
- #define cycleSize (frameCount / 2)
- #define twoPiOverCycleSize (205887/cycleSize)
-
- short i;
-
- for (i = 0; i < 32; i++)
- *wavyTable++ = (amplitude * Frac2Fix(FracSin(i * twoPiOverCycleSize))+32768) >> 16;
- }
-
- static void
- MapCoordinates(short width, short height, short x, short y,
- short *resultX, short *resultY,
- short frameNumber,
- short wavyTable[32])
- {
- *resultX = x;
- *resultY = y + wavyTable[(x + frameNumber) % 32];
-
- while (*resultX < 0)
- *resultX += width;
- while (*resultY < 0)
- *resultY += height;
-
- *resultX %= width;
- *resultY %= height;
- }
-
- /*
- Generate the addresses for one 32-pixel column.
- */
-
- static void
- GenerateMappingColumn(long *buffer1, short width, short height, short rowBytes,
- short frameNumber, short wavyTable[32])
- {
- long *offsetHere;
- short x, y;
-
- offsetHere = buffer1;
-
- for (y = 0; y < height; ++y) {
- for (x = 0; x < 32; ++x)
- {
- short destinationX, destinationY;
-
- destinationX = x;
- destinationY = y + wavyTable[(x + frameNumber) % 32];
-
- while (destinationX < 0)
- destinationX += width;
- while (destinationY < 0)
- destinationY += height;
-
- destinationX %= width;
- destinationY %= height;
-
- *offsetHere++ = (long)destinationY * rowBytes + destinationX;
- }
- }
- }
-
- //
- // Blit the entire bitmap from source to dest using a technique similar to what
- // we'd like to compile.
- //
- // Use 5 destination registers so we can use 16-bit constant offsets in instructions
- //
- long
- WriteSomeCode(short height, short rowBytes, long *mappingTable, short *placeForCode)
- {
- short i, x, y;
-
- long destRegisters[5];
- long targetByte;
- short *theCode = placeForCode;
-
- for (i = 0; i < 5; i++)
- destRegisters[i] = 32768 + i * 65536L;
-
- for (y = 0; y < height; ++y)
- {
- for (x = 0; x < 32; ++x) {
- long registerOffset;
-
- targetByte = *mappingTable++;
-
- for (i = 0; i < 5; i++) {
- registerOffset = targetByte - destRegisters[i];
- if (registerOffset >= -32768 && registerOffset < 32768) {
- switch(i) {
- case 0:
- *(*(short **) &theCode)++ = move_b_off_a5_to_a0;
- *(*(short **) &theCode)++ = x;
- *(*(short **) &theCode)++ = registerOffset;
- break;
- case 1:
- *(*(short **) &theCode)++ = move_b_off_a5_to_a1;
- *(*(short **) &theCode)++ = x;
- *(*(short **) &theCode)++ = registerOffset;
- break;
- case 2:
- *(*(short **) &theCode)++ = move_b_off_a5_to_a2;
- *(*(short **) &theCode)++ = x;
- *(*(short **) &theCode)++ = registerOffset;
- break;
- case 3:
- *(*(short **) &theCode)++ = move_b_off_a5_to_a3;
- *(*(short **) &theCode)++ = x;
- *(*(short **) &theCode)++ = registerOffset;
- break;
- case 4:
- *(*(short **) &theCode)++ = move_b_off_a5_to_a4;
- *(*(short **) &theCode)++ = x;
- *(*(short **) &theCode)++ = registerOffset;
- break;
- default:
- Debugger();
- ExitToShell();
- break;
- }
- goto gotRegister;
- }
- }
- // So, we have no register coverage for the destination
- // We’ll have to emit some slower code.
- registerOffset = targetByte - 32768;
- *(*(short **) &theCode)++ = immediate_long_load_d0;
- *(*(long **) &theCode)++ = registerOffset;
- *(*(short **) &theCode)++ = move_byte_da5_a0_d0_L;
- *(*(short **) &theCode)++ = x;
- *(*(short **) &theCode)++ = no_constant_for_load;
- gotRegister:
- ;
- }
- // add rowbytes to the row register
- *(*(short **) &theCode)++ = adda_w_const_a5;
- *(*(short **) &theCode)++ = rowBytes;
- }
- *(*(short **) &theCode)++ = rts;
- return (char *)theCode - (char *)placeForCode;
- }
-
- /* array with code */
-
- Boolean
- InitColumns(short amplitude, short width, short height, short rowBytes, short *frameCode[frameCount], Handle dialogItem)
- {
- long *columnMap;
- short frame;
- short wavyTable[32];
-
- MakeWavyTable(amplitude, wavyTable);
-
- columnMap = (long *)NewPtr(sizeof(long) * 32 * (long)height);
- if (columnMap == nil)
- return false;
-
- for (frame = 0; frame < frameCount; frame++)
- {
- Str255 frameNumberString;
- long size;
-
- /* update dialog status */
- NumToString(frame+1, frameNumberString);
- SetIText(dialogItem, frameNumberString);
-
- frameCode[frame] = (short *) NewPtr(12 * 32 * (long)height // move the rows
- + 6 * 20 * (long)height // the row reloads
- + 500); // el sloppolo
- if (frameCode[frame] == nil)
- return false;
-
- GenerateMappingColumn(columnMap, width, height, rowBytes, frame, wavyTable);
- size = WriteSomeCode(height, rowBytes, columnMap, frameCode[frame]);
- SetPtrSize((Ptr)frameCode[frame], size);
- }
-
- DisposePtr((Ptr)columnMap);
-
- FlushCache();
- return true;
- }
-
- void DrawColumn(char *sourceBase, char *destinationBase, short frameNumber, short *frameCode[frameCount])
- {
- short *code = frameCode[frameNumber];
-
- asm {
- movem.l a0-a6, -(sp)
-
- movea.l destinationBase, a0
- adda.l #0x8000, a0
- movea.l a0, a1
- adda.l #0x10000, a1
- movea.l a1, a2
- adda.l #0x10000, a2
- movea.l a2, a3
- adda.l #0x10000, a3
- movea.l a3, a4
- adda.l #0x10000, a4
- movea.l sourceBase, a5
-
- movea.l code, a6
- jsr (a6)
- movem.l (sp)+, a0-a6
- }
- }
-